import { ref } from 'vue'
import type { OrderData } from '@/types/order'
import { getOrderList } from '@/api/order'

export function useOrderTable() {
    const orderData = ref<OrderData[]>([])
    const currentPage = ref(1)
    const pageSize = ref(10)
    const total = ref(0)

    const getOrderListApi = async (params: {
        orderState: string,
        orderNumber: string,
        startDatetime: string,
        endDatetime: string
    }) => {
        const res = await getOrderList({
            pageSize: pageSize.value,
            pageNum: currentPage.value,
            ...params
        })
        orderData.value = res.data.list
        total.value = res.data.total
    }

    const handleSizeChange = (val: number) => {
        pageSize.value = val
    }

    const handleCurrentChange = (val: number) => {
        currentPage.value = val
    }

    return {
        orderData,
        currentPage,
        pageSize,
        total,
        getOrderListApi,
        handleSizeChange,
        handleCurrentChange
    }
}